<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>messageChannel</title>
  </head>
  <body>
    <script>
      let channel = new MessageChannel();
      let port1 = channel.port1;
      let port2 = channel.port2;
      port1.onmessage = function (event) {
        console.log("port1接收的数据：", event.data);
      };
      port2.onmessage = function (event) {
        console.log("port2接收的数据：", event.data);
      };
      port1.postMessage('port1发送数据');
      port2.postMessage('port2发送数据');
    </script>
  </body>
</html>
